package com.zpl.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zpl.order.entity.OrderDetails;
import com.zpl.order.mapper.OrderDetailsMapper;
import com.zpl.order.service.OrderDetailsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderDetailsServiceImpl implements OrderDetailsService {

    @Resource
    private OrderDetailsMapper orderDetailsMapper;

    @Override
    public boolean insert(OrderDetails orderDetails) {
        if(orderDetailsMapper.insert(orderDetails)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(Long id) {
        if(orderDetailsMapper.deleteById(id)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(OrderDetails orderDetails) {
        if(orderDetailsMapper.updateById(orderDetails)>0){
            return true;
        }
        return false;
    }

    @Override
    public OrderDetails selectById(Long id) {
        return orderDetailsMapper.selectById(id);
    }

    @Override
    public List<OrderDetails> selectByOrderId(Long orderId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("order_id", orderId);
        List<OrderDetails> list = orderDetailsMapper.selectList(queryWrapper);
        return list;
    }
}
